
import router from './router';
import {Message} from 'element-ui';
var ajax = function(func,data,method){
        return new Promise(function(resolve){
           let managerToken = localStorage.getItem("managerToken")
           if(!managerToken && !func=="login"){
               router.push('/login');
               return
           }
           xxcCloud.callFunction({
               name: 'shry',
               data: {
                 func:func,
                 data:data,
                 method:method || '',
                 token:managerToken
               },
           }).then(res=>{
               switch(res.result.code) {
                   case 200:
                      resolve(res.result.data)
                      break;
                   case 400:
                      Message.error({message: res.result.message});
                      break;
                   case 401:
                      Message.error({message: res.result.message});
                      router.push('/login');
                      break;
                   default:
                      Message.error({message: "未知错误"});
                      return
               }
           })
        })
    }
export default ajax
